package com.it.controller;


import com.it.entity.coverage.AiInsuranceCoverage;
import com.it.service.AiInsuranceCoverageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.R;

import java.util.List;

/**
 * <p>
 * 险种信息表 前端控制器
 * </p>
 *
 * @author lutao
 * @since 2025年09月17日
 */
@RestController
@RequestMapping("/coverage")
public class AiInsuranceCoverageController {
    @Autowired
    private AiInsuranceCoverageService aiInsuranceCoverageService;


    /**
     * 查询列表，支持分页、条件查询
     */
    @GetMapping("/list")
    public R list(@RequestParam(value="pageNum",defaultValue = "1",required = false) Integer pageNum,
                  @RequestParam(value="pageSize",defaultValue = "5",required = false) Integer pageSize,
                  @RequestParam(value = "coverageCode",required = false) String coverageCode,
                  @RequestParam(value="coverageName",required = false) String coverageName,
                  @RequestParam(value="coverageType",required = false) Integer coverageType,
                  @RequestParam(value="coverageStatus",required = false) Integer coverageStatus){
        return  aiInsuranceCoverageService.list(pageNum,pageSize,coverageCode,coverageName,coverageType,coverageStatus);
    }

    /**
     * 新增
     */
    @PostMapping
    public R add(@RequestBody AiInsuranceCoverage aiInsuranceCoverage){
        return aiInsuranceCoverageService.save(aiInsuranceCoverage) ? R.Success("新增成功",null) : R.Failed("新增失败");
    }
    /**
     * 更新
     */
    @PutMapping("/{id}")
    public R update(@PathVariable("id") Long id,@RequestBody AiInsuranceCoverage aiInsuranceCoverage){
        aiInsuranceCoverage.setCoverageId(id);
        return aiInsuranceCoverageService.updateById(aiInsuranceCoverage) ? R.Success("更新成功",null) : R.Failed("更新失败");

    }
    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Long id){
        return aiInsuranceCoverageService.removeById(id) ? R.Success("删除成功",null) : R.Failed("删除失败");
    }
    /**
     * 更新险种状态
     */
    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable("id") Long id,@PathVariable("status") Integer coverageStatus){
        AiInsuranceCoverage aiInsuranceCoverage = new AiInsuranceCoverage();
        aiInsuranceCoverage.setCoverageId(id);
        aiInsuranceCoverage.setCoverageStatus(coverageStatus);
        return aiInsuranceCoverageService.updateById(aiInsuranceCoverage) ? R.Success("更新状态成功",null) : R.Failed("更新状态失败");
    }



    /**
     * 查询所有险种的名称列表，用于下拉选择
     */
    @GetMapping("/names/{coverageType}")
    public R getCoverageNames(@PathVariable("coverageType") Integer coverageType){
        return aiInsuranceCoverageService.listCoverageNames(coverageType);
    }

    /**
     * 根据险种名称查询险种险种单位保额
     */
    @GetMapping("/unitInsured/{coverageName}")
    public R getUnitInsuredAmount(@PathVariable("coverageName") String coverageName){
        return aiInsuranceCoverageService.getUnitInsuredAmount(coverageName);
    }




}
